import Mock from "mockjs"

// const { data } = Mock.mock({
//   "data|100": [
//     {
//       "number|10000000000-19999999999": 1
//     }
//   ]
// })


// 存放数据
let { userInfo } = Mock.mock({
  'userInfo': [{
    username: '老板',
    tel: '12345678900',
    password: '123456',
    'id': '@id',
    'img': '@image("150x150","@color","❥(^_-)")',
  }]
})
//   验证账号密码
Mock.mock('/user/login', 'post', (config) => {
  const req = JSON.parse(config.body)

  let res = {
    code: '200',
    msg: '登陆失败',
    id: '',
    img: '',
    tel: '',
    username: ''
  }
  // 判断对错返回数据
  userInfo.forEach(item => {
    if (item.tel == req.tel && item.password == req.password) {
      res.msg = '登录成功'
      res.id = item.id
      res.img = item.img
      res.tel = item.tel
      res.username = item.userName
      res.code = '200'
    } else {
      res.code = '300'
      res.msg = '登陆失败'
    }
  });
  return res
})

// 注册账号密码
Mock.mock('/user/docheckphone', 'post', (config) => {
  const req = JSON.parse(config.body)
  //console.log('111',req);

  let res = {
    code: '10005',
    msg: '注册失败,不能重复注册',
  }
  userInfo.forEach(item => {
    console.log(item);
    if (item.tel == req.tel) {
      res.code = '10005'
      res.msg = '注册失败,不能重复注册'
    } else {
      userInfo.push({
        tel: req.tel,
        password: '',
        id: Mock.mock('@id'),
        img: Mock.mock('@image("150x150","@color","年轻")'),
        username: Mock.mock('@cword(3)')
      })
      res.code = '200'
      res.msg = '注册成功'
    }
  });

  return res
})

// 发送验证码
Mock.mock('/user/dosendmsgcode', 'post', (config) => {
  const req = JSON.parse(config.body)

  userInfo.push({
    telcode: Mock.mock('@string("number", 5)'),
    id: Mock.mock('@id'),
    img: Mock.mock('@image("150x150","@color","嗨嗨害")'),
    username: Mock.mock('@cword(3)'),
    tel: req.tel
  })
  let res = {
    code: '300',
    msg: '发送失败',
    telcode: ''
  }
})